package au.edu.unsw.infs3634.gamifiedlearning;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Filterable;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;

import java.util.List;

import au.edu.unsw.infs3634.gamifiedlearning.API.Country;

public class QuestionAdapter extends RecyclerView.Adapter<QuestionAdapter.QuestionViewHolder> {
    private List<Question> mQuestion;
    private RecyclerviewClickListener mListener;

    public QuestionAdapter(List<Question> question, QuestionAdapter.RecyclerviewClickListener listener){
        mQuestion = question;
        mListener = listener;
    }

    public interface RecyclerviewClickListener{
        void onClick(View view, String id);
    }
    @NonNull
    @Override
    public QuestionAdapter.QuestionViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.quiz_question_row, parent, false);
        return new QuestionAdapter.QuestionViewHolder(view, mListener);
    }

    @Override
    public void onBindViewHolder(@NonNull QuestionViewHolder holder, int position) {
        Question question = mQuestion.get(position);

        holder.mQuestionText.setText(question.getQuestion());
        holder.mQuestionAns1.setText(question.getQuestionans1());
        holder.mQuestionAns2.setText(question.getQuestionans2());
        holder.mQuestionAns3.setText(question.getQuestionans3());
        holder.mQuestionAns4.setText(question.getQuestionans4());
    }

    @Override
    public int getItemCount() {
        return mQuestion.size();
    }

    public static class QuestionViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
        private QuestionAdapter.RecyclerviewClickListener mListener;
        public TextView mQuestionText, mQuestionAns1, mQuestionAns2, mQuestionAns3, mQuestionAns4;


        public QuestionViewHolder(@NonNull View itemView, QuestionAdapter.RecyclerviewClickListener listener) {
            super(itemView);
            mListener = listener;
            mQuestionText = itemView.findViewById(R.id.tvQuestion);
            mQuestionAns1 = itemView.findViewById(R.id.rBtnA);
            mQuestionAns2 = itemView.findViewById(R.id.rBtnB);
            mQuestionAns3 = itemView.findViewById(R.id.rBtnC);
            mQuestionAns4 = itemView.findViewById(R.id.rBtnD);
            itemView.setOnClickListener(this);
        }
        @Override
        public void onClick(View v) {
            mListener.onClick(v, (String) v.getTag());
            Log.d("Test",(String) v.getTag());
        }
    }
}
